<template>
	<view class="information">
		<view class="searchBox">
			<view class="searchInner">
				<image class="searchicon" src="../../static/image/searchIcon.png" mode="" style=""></image>
				<input class="inputiem" type="text" v-model="searchValue" placeholder="请输入搜索词" />
				<view class="searchBtn" @click="handleSearch">
					搜索
				</view>
			</view>
		</view>

		<view class="typeBox">
			<view class="typeitem" v-for="(item,index) in typeList" @click="handleChangetype(item,index)">
				<view :class="currIndex==index?'texted':''">
					{{item.title}}
				</view>
				<view v-if="currIndex==index" class="heng"></view>
			</view>
		</view>

		<view v-if="dataList.length>0" class="dataListbox">
			<view class="dataItem" v-for="(item,index) in dataList" @click="handleDetail(item)">
				<image :src="item.image" mode=""
					style="width: 160rpx;height: 160rpx;border-radius: 8rpx 8rpx 8rpx 8rpx;"></image>
				<view class="rightBox">
					<view class="title">
						{{item.title}}
					</view>
					<view class="time">
						发布时间 {{item.updated_at}}
					</view>
				</view>
			</view>

		</view>


		<view v-if="dataList.length==0" class="nullBox">
			<image src="../../static/image/nullimg.png" style="width: 148rpx;height: 148rpx;" mode=""></image>
			<view class="">
				暂无资讯
			</view>
		</view>

	</view>
</template>

<script>
	import {
		indexCategory,
		activityIndex
	} from "@/api/api.js"
	export default {
		data() {
			return {
				searchValue: "",
				typeList: [{
						name: "推荐阅读",
						id: 1
					},
					{
						name: "选校指南",
						id: 2
					},
					{
						name: "国际课程",
						id: 3
					},
				],
				currIndex: 0,
				class_id: null,
				dataList: [],
			}
		},
		async onLoad() {
			await this.handleGetindexCategory()
			await this.handleActivityIndex()
		},
		async onShow() {
			// await this.handleGetindexCategory()
			// await this.handleActivityIndex()
		},
		onPullDownRefresh() {
			// console.log("触发了下拉刷新"),
			this.handleActivityIndex()
			uni.stopPullDownRefresh();
		},
		methods: {
			async handleGetindexCategory() {
				let res = await indexCategory()
				// console.log("资讯分类", res)
				this.typeList = res.data
				this.class_id = this.typeList[0].id
			},
			async handleActivityIndex() {
				let res = await activityIndex({
					class_id: this.class_id,
					name: this.searchValue
				})
				this.dataList = res.data.data
			},
			handleChangetype(item, index) {
				this.currIndex = index
				this.class_id = this.typeList[index].id
				this.handleActivityIndex()
			},
			handleSearch() {
				this.handleActivityIndex()
			},
			handleDetail(item) {
				uni.navigateTo({
					url: `./detail?id=${item.id}`
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.information {

		.searchBox {
			width: 100%;
			height: 100rpx;
			background: #FFFFFF;

			.searchInner {
				width: 690rpx;
				height: 80rpx;
				background: #F6F6F6;
				border-radius: 200rpx 200rpx 200rpx 200rpx;
				margin: 0 auto;
				display: flex;
				align-items: center;

				.searchicon {
					width: 30rpx;
					height: 30rpx;
					// margin-top: 24rpx;
					margin-left: 30rpx;
				}

				.inputiem {
					width: 450rpx;
					margin-left: 20rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					line-height: 42rpx;
					font-size: 30rpx;
				}

				.searchBtn {
					width: 154rpx;
					height: 72rpx;
					background: #255A9B;
					border-radius: 200rpx 200rpx 200rpx 200rpx;
					font-size: 30rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 72rpx;
					text-align: center;
				}

			}

		}

		.typeBox {
			width: 100%;
			height: 100rpx;
			background: #FFFFFF;
			padding-top: 30rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-around;
			font-size: 30rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #333333;
			line-height: 30rpx;

			.typeitem {
				display: flex;
				flex-direction: column;
				align-items: center;
			}

			.texted {
				color: #255A9B;
				font-weight: 500;
			}

			.heng {
				width: 52rpx;
				height: 8rpx;
				background: #255A9B;
				border-radius: 200rpx 200rpx 200rpx 200rpx;
				margin-top: 30rpx;
			}
		}

		.nullBox {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #AEB8C2;
			line-height: 28rpx;
			width: 148rpx;
			text-align: center;
			margin: 0 auto;
			margin-top: 200rpx;
		}

		.dataListbox {
			width: 100%;
			margin-top: 20rpx;

			.dataItem {
				width: 100%;
				height: 220rpx;
				background: #FFFFFF;
				display: flex;
				padding: 30rpx;
				box-sizing: border-box;
				margin-bottom: 20rpx;
				justify-content: space-between;

				.rightBox {
					width: 510rpx;
					// height: 72rpx;
					font-size: 30rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #212121;
					line-height: 35rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.title {
						font-size: 30rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #212121;
						line-height: 35rpx;
					}

					.time {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #999999;
						line-height: 28rpx;
						margin-top: 54rpx;
					}
				}
			}
		}

	}
</style>